package com.github.data_manage

import com.github.data_manage.domain.po.FundDepthResearchAttach
import java.math.BigDecimal
import java.time.LocalDate
import kotlin.reflect.KMutableProperty
import kotlin.reflect.full.memberProperties

/**
 *
 * @author chenhainan
 * @since 2025/8/11
 */
class ReflectTest {
}

fun main() {
    val fundDepthResearchAttach = FundDepthResearchAttach(1, LocalDate.now())
    val clazz = FundDepthResearchAttach::class
    val value = "1"
    for (property in clazz.memberProperties) {
        val propertyName = property.name
        val propertyIndex = FundDepthResearchAttach.propertyIndexMap.getOrDefault(propertyName, -1)
        if (propertyIndex == -1) {
            continue
        }
        if (property is KMutableProperty<*>) {
            val actualValue = if (value == null && property.returnType.isMarkedNullable) {
                null
            } else {
                // 尝试类型转换
                when (property.returnType.classifier) {
                    String::class -> value as String?
                    BigDecimal::class -> BigDecimal(value)
                    else -> value
                }
            }
            property.setter.call(fundDepthResearchAttach, actualValue)

        }
    }
    println(fundDepthResearchAttach)
}